package hu.bme.mit.inf.expendables.entities;
	
import javax.persistence.*;
import hu.bme.mit.inf.expendables.entities.*;
import java.util.List;
import java.util.ArrayList;


@Entity
@Table(name="T_APPMETADATA")
@NamedQueries(
	{
	@NamedQuery(name=AppMetadata.GET_ALLAPPMETADATA,query="SELECT a FROM AppMetadata a WHERE (a.supervision.hasBeenSupervised_appName = TRUE) AND (a.supervision.hasBeenSupervised_appTest = TRUE) AND (a.supervision.hasBeenSupervised_metadata = TRUE)"),
	@NamedQuery(name=AppMetadata.GET_ALLAPPMETADATAUNSUPERVISED,query="SELECT a FROM AppMetadata a"),
	@NamedQuery(name=AppMetadata.GET_APPMETADATA_CAT,query="SELECT a FROM AppMetadata a WHERE (a.category = :category) AND (a.supervision.hasBeenSupervised_appName = TRUE) AND (a.supervision.hasBeenSupervised_appTest = TRUE) AND (a.supervision.hasBeenSupervised_metadata = TRUE)"),
	@NamedQuery(name=AppMetadata.GET_APPMETADATA_ID,query="SELECT a FROM AppMetadata a WHERE (a.appMetadataId = :appMetadataId) AND (a.supervision.hasBeenSupervised_appName = TRUE) AND (a.supervision.hasBeenSupervised_appTest = TRUE) AND (a.supervision.hasBeenSupervised_metadata = TRUE)"),
	@NamedQuery(name=AppMetadata.GET_APPMETADATAUNSUPERVISED_ID,query="SELECT a FROM AppMetadata a WHERE a.appMetadataId = :appMetadataId"),
	@NamedQuery(name=AppMetadata.GET_APPMETADATA_NAME,query="SELECT a FROM AppMetadata a WHERE (UPPER(a.name) LIKE :name) AND (a.supervision.hasBeenSupervised_appName = TRUE) AND (a.supervision.hasBeenSupervised_appTest = TRUE) AND (a.supervision.hasBeenSupervised_metadata = TRUE)"),
	@NamedQuery(name=AppMetadata.UPDATE_APPMETADATA,query="UPDATE AppMetadata a SET a.name = :name, a.version = :version, a.description = :description, a.uploaddate = :uploaddate, a.category = :category, a.price = :price, a.ageLimit = :agelimit WHERE a.appMetadataId = :appMetadataId"),
	@NamedQuery(name=AppMetadata.DELETE_APPMETADATA,query="DELETE FROM AppMetadata a WHERE a.appMetadataId = :appMetadataId")
	})
public class AppMetadata {
	                        	
	public static final String GET_ALLAPPMETADATA = "GetAllAppMetadata";
	public static final String GET_ALLAPPMETADATAUNSUPERVISED = "GetAllAppMetadataUnsupervised";
	public static final String GET_APPMETADATA_CAT = "GetAppMetadataByCategory";
	public static final String GET_APPMETADATA_ID = "GetAppMetadataById";
	public static final String GET_APPMETADATAUNSUPERVISED_ID = "GetAppMetadataUnsupervisedById";
	public static final String GET_APPMETADATA_NAME = "GetAppMetadataByName";
	public static final String UPDATE_APPMETADATA = "UpdateAppMetadata";
	public static final String DELETE_APPMETADATA = "DeleteAppMetadata";

	//Attributes
	private String name;
	
	private String version;
	
	@Temporal(TemporalType.TIMESTAMP)
	private java.util.Date uploaddate;
	
	private String description;
	
	private float price;
	
	private Category category;
	
	@Id
	@GeneratedValue
	@Column(name="APPMETADATA_ID")
	private long appMetadataId;
	
	private int ageLimit;
	

	//Reference to App
	@OneToOne
	@JoinColumn(name = "APP_ID")
	private App app;
	
	//Reference to AppSupervision
	@OneToOne
	@JoinColumn(name = "APPSUPERVISION_ID")
	private AppSupervision supervision;
	
	//Reference to Developer
	@ManyToOne
	@JoinColumn(name = "DEVELOPER_ID")
	private Developer developer;
	
	//Reference to Customer
	@ManyToMany
	@JoinTable(name = "APPMETADATAOWNERS", joinColumns = @JoinColumn(name = "APPMETADATA_ID"), inverseJoinColumns = @JoinColumn(name = "USER_ID"))
	private List<Customer> owners= new ArrayList<Customer>();
	
	//Reference to Transaction
	@OneToMany(mappedBy="appMetadata")
	private List<Transaction> transactions= new ArrayList<Transaction>();
	


	//Getters and Setters
	public String getName(){
		return name;
	}
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getVersion(){
		return version;
	}
	
	public void setVersion(String version){
		this.version = version;
	}
	
	public java.util.Date getUploaddate(){
		return uploaddate;
	}
	
	public void setUploaddate(java.util.Date uploaddate){
		this.uploaddate = uploaddate;
	}
	
	public String getDescription(){
		return description;
	}
	
	public void setDescription(String description){
		this.description = description;
	}
	
	public float getPrice(){
		return price;
	}
	
	public void setPrice(float price){
		this.price = price;
	}
	
	public Category getCategory(){
		return category;
	}
	
	public void setCategory(Category category){
		this.category = category;
	}
	
	public long getAppMetadataId(){
		return appMetadataId;
	}
	
	public void setAppMetadataId(long appMetadataId){
		this.appMetadataId = appMetadataId;
	}
	
	public int getAgeLimit(){
		return ageLimit;
	}
	
	public void setAgeLimit(int ageLimit){
		this.ageLimit = ageLimit;
	}
	

	public App getApp(){
		return app;
	}
	
	public void setApp(App app){
		this.app = app;
	}
		
	public AppSupervision getSupervision(){
		return supervision;
	}
	
	public void setSupervision(AppSupervision supervision){
		this.supervision = supervision;
	}
		
	public Developer getDeveloper(){
		return developer;
	}
	
	public void setDeveloper(Developer developer){
		this.developer = developer;
	}
		
	public List<Customer> getOwners(){
		return owners;
	}
	
	public void setOwners(List<Customer> owners){
		this.owners = owners;
	}
		
	public List<Transaction> getTransactions(){
		return transactions;
	}
	
	public void setTransactions(List<Transaction> transactions){
		this.transactions = transactions;
	}
		
}